package youcaihuaoa.weetop.com.ui.adapter

import android.os.Bundle
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.common.api.GlBaseApi
import com.robot.base.configs.AppConstants
import com.robot.base.model.FileBean
import com.robot.base.util.arouter.ARouterUtil
import com.robot.base.utils.pic.ImageLoaderUtils
import youcaihuaoa.weetop.com.R

class FolderInfoAdapter(var status: Boolean = false) :
    BaseQuickAdapter<FileBean, BaseViewHolder>(R.layout.app_item_folder_info) {
    override fun convert(holder: BaseViewHolder, item: FileBean) {
        when (item.file_type) {
            "JPG", "PNG", "jpg", "png", "HEIC", "heic", "jpeg", "JPEG" -> {
                holder.setGone(R.id.item_iv_img, false)
                    .setGone(R.id.item_iv_icon, true)
                    .setGone(R.id.item_tv_name, true)
                    .setGone(R.id.item_tv_select, true)
                ImageLoaderUtils.displayRound(
                    context,
                    holder.getView(R.id.item_iv_img),
                    item.file_path,
                    6
                )
            }
            else -> {
                holder.setGone(R.id.item_iv_img, true)
                    .setGone(R.id.item_iv_icon, false)
                    .setGone(R.id.item_tv_name, false)
                    .setGone(R.id.item_tv_select, false)
                    .setText(R.id.item_tv_name, item.file_type)
            }
        }

        holder.setGone(R.id.item_iv_close, status)

        holder.getView<AppCompatImageView>(R.id.item_iv_close)
            .setOnClickListener {
                removeAt(holder.adapterPosition)
            }

        holder.getView<AppCompatImageView>(R.id.item_iv_img)
            .setOnClickListener {
                ARouterUtil.goToActivityWithBundle(
                    AppConstants.Router.Main.A_BIG_IMG,
                    Bundle().apply {
                        putString(
                            AppConstants.BundleKey.IMG_URL,
                            GlBaseApi.PIC_BASE_URL + "${item.file_path}"
                        )
                    })
            }

        holder.getView<AppCompatTextView>(R.id.item_tv_select).setOnClickListener {
            ARouterUtil.goToActivityWithBundle(AppConstants.Router.Main.A_WEB, Bundle().apply {
                putSerializable(
                    AppConstants.BundleKey.WEB_URL,
                    GlBaseApi.WEB_URL + GlBaseApi.PIC_BASE_URL + "${item.file_path}"
                )
            })
        }
    }
}